package cn.kafka;

import java.util.Properties;

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public class ProducerDemo {
		public static void main(String[] args) throws Exception {
				Properties props = new Properties();
				props.put("zk.connect", "qiqi:2181,slave1:2181,slave2:2181");
				props.put("metadata.broker.list", "qiqi:9092,slave1:9092,slave2:9092");
				props.put("serializer.class", "kafka.serializer.StringEncoder");
				ProducerConfig config = new ProducerConfig(props);
				Producer<String,String> producer = new Producer<String,String>(config);
				
				//发送业务消息
				//读取文件 读取内存数据库 读 socket端口
				for (int i = 0; i <=1000; i++) {
					Thread.sleep(500);
					producer.send(new KeyedMessage<String,String>("myl", "i love you " + i +"times"));
				}
		}
}
